<template>
  <!-- 编制材料复试月报表格 -->
  <list-table ref="table" tableLayout="fixed" size="default" :columns="columns" :request="loadData">
    <template slot="actions" slot-scope="text, record">
      <service-export-mould
        v-btnPermission="[[
                      {
                        ident: 'prma_seex',
                        code: 'seex_qm_052_prexp_04'
                      },
                      {
                        ident: 'prma_buco',
                        code: 'buco_qm_052_prexp_04'
                      }
              ],[
                      {
                        ident: 'prma_seex',
                        code: 'seex_qm_052_brexp_03'
                      },
                      {
                        ident: 'prma_buco',
                        code: 'buco_qm_052_brexp_03'
                      }
              ],[
                      {
                        ident: 'prma_seex',
                        code: 'seex_qm_052_cmexp_02'
                      },
                      {
                        ident: 'prma_buco',
                        code: 'buco_qm_052_cmexp_02'
                      }
              ]][orgLevel]"
        class="ml12"
        :isButton="false"
        :serviceiUrl="qualityApiUrl"
        icon="cloud-download"
        :requestParams="{ mark: orgLevel, id: record.id }"
        url="/quality/month/experiment/excel"
        buttonText="导出"
      ></service-export-mould>
      <!-- <a v-btnPermission="'qm_041_loo_04'" @click="handleManage(0, record)">导出</a> -->
    </template>
  </list-table>
</template>

<script>
import { qualityApiUrl } from '@/api/config.js'
import ServiceExportMould from '@/components/ServiceExportMould'

export default {
  name: 'MonthlyMeterialReportTable',
  props: {
    // 请求接口
    api: {
      type: Object,
      default: () => null
    },
    // 表格的组织层级：公司级，分公司级，项目部级
    orgLevel: {
      type: [Number, String],
      default: () => 0
    }
  },
  components: {
    ServiceExportMould
  },
  data() {
    return {
      qualityApiUrl,
      editModel: 0, //  操作类型
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, { ...this.queryParam, mark: this.orgLevel })
        return this.api?.postList(requestParameters).then((res) => {
          return res
        })
      }
    }
  },
  computed: {
    // 表头
    columns() {
      let columns = [
        {
          title: '序号',
          width: '80px',
          dataIndex: 'index',
          customRender() {
            return arguments[2] + 1
          }
        }
      ]
      if (this.orgLevel === 0) {
        columns.push(
          {
            title: '分公司',
            ellipsis: true,
            dataIndex: 'name'
          },
          {
            title: '项目',
            ellipsis: true,
            dataIndex: 'projectName'
          }
        )
      } else {
        columns.push({
          title: ['分公司', '组织'][this.orgLevel - 1],
          ellipsis: true,
          dataIndex: 'name'
        })
      }
      columns.push(
        {
          title: '月报时间',
          ellipsis: true,
          dataIndex: 'monthlyReportDate'
        },
        {
          title: '本期送检数量',
          ellipsis: true,
          dataIndex: 'submitForInspectionNum'
        },
        {
          title: '本期不合格数量',
          align: 'center',
          ellipsis: true,
          dataIndex: 'thisTimeUnqualifiedNum'
        },
        {
          title: '自开工累计送检数量',
          align: 'center',
          dataIndex: 'allSubmitForInspectionNum'
        },
        {
          title: '自开工累计不合格数量',
          align: 'center',
          dataIndex: 'allUnqualifiedNum'
        },
        {
          title: '操作',
          dataIndex: 'actions',
          width: '150px',
          fixed: 'right',
          align: 'center',
          scopedSlots: { customRender: 'actions' }
        }
      )
      return columns
    }
  },
  methods: {
    // 搜索
    search(value) {
      value && (this.queryParam = value)
      this.$refs.table.refresh(true)
    },
    // 操作栏
    handleManage(type, record) {
      this.editModel = type
      let query = {
        editModel: type
      }
      if (record && record.id) {
        query.id = record.id
      }
      this.$router.push({
        name: 'QCActivityRegistrationEdit',
        query
      })
    }
  }
}
</script>
